//
//  FullScreenImageBrowserView.m
//  yilutongxing
//
//  Created by T&J on 2017/12/2.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "FullScreenImageBrowserView.h"

@implementation FullScreenImageBrowserView

-(instancetype)initWithImage:(UIImage*)image{
    self = [super init];
    if (self) {
        self.backgroundColor = COLOR_ALPHA(8, 8, 8, 0.7);
        
        CGFloat SW = SCREEN_WIDTH;
        CGFloat SH = SCREEN_HEIGHT;
        CGFloat SR = SH/SW;
        [self setFrame:CGRectMake(0, 0, SW, SH)];
        CGFloat imgWidth = CGImageGetWidth(image.CGImage);
        CGFloat imgHeight = CGImageGetHeight(image.CGImage);
        CGFloat imgRate = imgHeight/imgWidth;
        if (imgRate<=SR) {
            imgWidth = SW;//imgWidth*(SH/imgHeight);
            imgHeight = imgWidth*imgRate;
        }
        else {
            imgWidth = SH/imgRate;
            imgHeight = SH;//imgHeight*(SW/imgWidth);
        }
        UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake((SW-imgWidth)/2, (SH-imgHeight)/2, imgWidth, imgHeight)];
        [iv setImage:image];
        [self addSubview:iv];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(OnTapSelf)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)OnTapSelf{
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
